<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
</head>
<body>
<div id="app">
    <button @click="unWatch">取消监听</button>
    <button @click="count++">监听count</button>
    <p>{{count}}</p>
</div>
<script>
    Vue.config.productionTip = false
    const vm = new Vue({
        el: '#app',
        data() {
            return {
              count:1
            }
        },
        methods:{
            unWatch:()=>{}
        },
      watch:{
      //      1.第一种监听方式
      //     count(){
      //         console.log('count改变了')
      //     },
      //    2.深度监听
      //     count:{
      //         immediate:true,
      //         handler(){
      //             console.log('count改变了')
      //         }
      //     }
      }
    })


//    3.在外部监听
    vm.unWatch = vm.$watch('count',function (newVal,oldVal){
        console.log('count改变了')
        console.log(newVal,oldVal)
    },{immediate:true})
</script>
</body>
</html>